package com.design.cjm.behavioral.observer.example;

import java.util.Objects;

/**
 * 抽象观察者
 *
 * @Author: Jie Ming Chen
 * @Date: 2018/9/24
 * @Version 1.0
 */
public abstract class Observer {

    protected String name;

    protected Subject sub;

    public Observer(String name, Subject sub) {

        this.name = name;
        this.sub = sub;
    }

    public abstract void update();

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Observer observer = (Observer) o;
        return Objects.equals(name, observer.name) &&
                Objects.equals(sub, observer.sub);
    }

    @Override
    public int hashCode() {

        return Objects.hash(name, sub);
    }
}
